package com.zz.service;

import java.util.List;
import java.util.Optional;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.zz.entity.Ware;
import com.zz.repository.WareRepository;

@Service
public class WareService {
	@Resource
	WareRepository wareRepository;
	//分页查询
	public Page<Ware> findAll(String page,String limit){
		Pageable pageable=PageRequest.of(Integer.parseInt(page), Integer.parseInt(limit));
		Page<Ware> pageinfo=wareRepository.findAll(pageable);
		return pageinfo;
	}
	//根据id查找
	public Optional<Ware> findById(String id) {
		return wareRepository.findById(id);
	}
	//根据名字查找
	public List<Ware> findByName(String name){
		return wareRepository.findByNameLike("%"+name+"%");
	}
	//查询仓库信息ByName
	public Ware findwareByname(String name) {
		return wareRepository.findByName(name);
	}
	//修改
	public Ware updateware(Ware ware) {
		return wareRepository.save(ware);
	}
	//删除
	public void deleteById(String id) {
		wareRepository.deleteById(id);
	}
	//添加
	public Ware saveware(Ware w) {
		return wareRepository.save(w);
	}
}
